
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>评论列表</title>
<style type="text/css">
#user_fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}

.fitem input {
	width: 160px;
}
</style>


<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/themes/color.css">
<link rel="stylesheet" type="text/css"
	href="jquery-easyui-1.4.1/demo/demo.css">
<script type="text/javascript" src="jquery-easyui-1.4.1/jquery.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="jquery-easyui-1.4.1/locale/easyui-lang-zh_CN.js"></script>

</head>
<body>
	<!-- <div class="tableFind">
	   <p>
		<label>日期</label>&nbsp;&nbsp;
		<input type="text" id="commentTime" class="easyui-datebox"
			onkeydown="if(event.keyCode==13) searchMessage()" />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		
	    <label>状态</label>&nbsp;&nbsp;
	    <input type="text" id="state" class="easyui-textbox"
			onkeydown="if(event.keyCode==13) searchMessage()" />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

		<a id="btn"
					href="javascript:searchComment()" class="easyui-linkbutton tableFindBut"
					data-options="iconCls:'icon-search'" onclick="obj.find()">查询	
		</a></p>
	</div> -->
	<table id="user_dg" class="easyui-datagrid" style="height: 470px;"
		url="${pageContext.request.contextPath}/admin/Comment/findAll.do"
		toolbar="#user_toolbar" pagination="true" rownumbers="true"
		fitColumns="true" singleSelect="true"
		data-options="fit:false,border:false,pageSize:10,pageList:[10,20,30,40]">
		<thead>

			<!-- 管理表格-表头的修改 -->
			<tr>
			<th field="cb" checkbox="true" align="center"></th>
            <th field="commentNo" width="50" align="center">评论编号</th>
            
           <!--  <th field="foodNo" width="50" align="center">美食编号</th> -->
            <th field="foodNo" formatter="foodNameFormat" width="80">美食名称</th>
            
            <th field="commContent" width="50" align="center">评论内容</th>
            
            <!-- <th field="userNo" width="50" align="center">会员编号</th> -->
            <th field="userNo" formatter="userFormat" width="80">发布作者</th>
            
            <th field="commentTime" width="50" align="center">评论时间</th>
            <th field="state" width="150" align="center">状态</th>
			</tr>
		</thead>
	</table>
	<div id="user_toolbar">
		<a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editComment()">编辑</a>  <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="destroyComment()">删除</a>
	</div>
	<div id="user_dlg" class="easyui-dialog" style="padding: 10px 20px";
		closed="true" buttons="#user_dlg-buttons">
		<div class="ftitle">详细信息</div>
		<form id="user_fm" method="post" novalidate>
			<div class="fitem">
				<!-- <label>美食编号:</label> <input name="foodNo" class="easyui-textbox"
					required="true">
			</div> -->
			<label>美食名称:</label>
				<input id="id_foodName"  name="food.foodNo" valueField="foodNo"
					textField="foodName" required="true" editable="false" url="${pageContext.request.contextPath}/admin/Food/findList.do"
					class="easyui-combobox" readonly="readonly">
			</div>
			
			<div class="fitem">
				<label>评论内容:</label> <input name="commContent" class="easyui-textbox" readonly="readonly">
			</div>
			<!-- <div class="fitem">
				<label>会员编号:</label> <input name="userNo" class="easyui-textbox">
			</div> -->
			<div class="fitem">
			<label>发布作者:</label>
				<input id="id_userMessage"  name="userMessage.userNo" valueField="userNo"
					textField="userName" required="true" editable="false" url="${pageContext.request.contextPath}/UserMessage/findList.do"
					class="easyui-combobox" readonly="readonly">
			</div>
			<div class="fitem">
				<label>评论时间:</label> <input name="commentTime" class="easyui-datebox"
					validType="date" readonly="readonly">
			</div>
			<div class="fitem">
				<label>状态:</label> <input name="state" class="easyui-textbox">
			</div>
		</form>
	</div>
	<div id="user_dlg-buttons">
		<a href="javascript:void(0)" class="easyui-linkbutton c6"
			iconCls="icon-ok" onclick="saveComment()" style="width: 90px">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-cancel"
			onclick="javascript:$('#user_dlg').dialog('close')"
			style="width: 90px">取消</a>
	</div>
	<script type="text/javascript">
	
	//模糊查询
		function searchfood(){
		var state = $.trim($('#state').val());		//获取搜索框的内，$.trim()可以消除前后空格
		
		if(state==""){state=null;
		
		}else{
			$('#user_dg').datagrid('load', {
				state : $('#state').val()
			});
		}	
		
	}
	
	 
	function foodNameFormat(value, row, rowindex) {
		return row.food.foodName;
	}
	
	function userFormat(value, row, rowindex) {
		return row.userMessage.userName;
	}
	
	//重新设置easy ui的时间格式
	$.fn.datebox.defaults.formatter=function(date){
		var y=date.getFullYear();
		var m=date.getMonth()+1;
		var d=date.getDate();
		return y+'/'+m+'/'+d;
	}
	$.fn.datebox.defaults.parser=function(date){
		if(date){
			return new Date(date)
		}else{
			return new Date();
		}
	}
	
		var url;
		function newComment() {
			$('#user_dlg').dialog('open').dialog('setTitle', '新增');
			$('#user_fm').form('clear');//清除表单数据
			url = '${pageContext.request.contextPath}/admin/Comment/addComment.do';//新增调用的网址
		}
		function editComment() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$('#user_dlg').dialog('open').dialog('setTitle', '编辑');
				$('#user_fm').form('clear');//清除表单数据
				$('#user_fm').form('load', row);
				url = '${pageContext.request.contextPath}/admin/Comment/updateComment.do?commentNo=' + row.commentNo;
			}
			
			var fooddata = $('#id_foodName').combobox('getData');
		    if(fooddata.length>0){
		    	//编辑窗口默认选中正在编辑的数据
			  $('#id_foodName').combobox('select',row.food.foodNo);
		    }; 
		    
		    var userMessagedata = $('#id_userMessage').combobox('getData');
		    if(userMessagedata.length>0){
			  $('#id_userMessage').combobox('select',row.userMessage.userNo);
		    }; 
			
		}
		function saveComment() {
			$('#user_fm').form('submit', {
				url : url,
				onSubmit : function() {
					return $(this).form('validate');
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.errorMsg) {
						$.messager.show({
							title : 'Error',
							msg : result.errorMsg
						});
					} else {
						$('#user_dlg').dialog('close'); // close the dialog
						$('#user_dg').datagrid('reload'); // reload the user data
					}
				}
			});
		}
		function destroyComment() {
			var row = $('#user_dg').datagrid('getSelected');
			if (row) {
				$.messager.confirm('Confirm', '确定要删除吗?', function(r) {
					if (r) {
						//ajax调用--异步通信调用
						$.post('${pageContext.request.contextPath}/admin/Comment/deleteComment.do', {
							commentNo : row.commentNo
						}, function(result) {
							if (result.success) {
								$('#user_dg').datagrid('reload'); // reload the user data
							} else {
								$.messager.show({ // show error message
									title : 'Error',
									msg : result.errorMsg
								});
							}
						}, 'json');//回调函数
					}
				});
			}
		}
	</script>

</body>
</html>